﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tool;

namespace AutoMachine
{
    internal partial class Frm_PassWord : Form
    {

        #region 窗体实例化
        /// <summary>
        /// 窗体对象实例化
        /// </summary>
        private static Frm_PassWord _instance;
        internal static Frm_PassWord Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Frm_PassWord();
                return _instance;
            }
        }
        #endregion


        public Frm_PassWord()
        {
            InitializeComponent();      
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            this.cboUserName.SelectedIndex = 0;
        }

        //修改按钮
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.oldPassWord.Text == string.Empty || this.newPassWord.Text == string.Empty || this.confirmPassWord.Text == string.Empty)
            {
                MessageBox.Show("请输入密码");
            }
            else if (this.cboUserName.Text == "管理员" && this.oldPassWord.Text == Tool.IniFile.INIGetStringValue(SysConfig.ConfigPath, "Config", "管理员", ""))
            {
                if (this.newPassWord.Text == this.confirmPassWord.Text)
                {
                    Tool.IniFile.INIWriteValue(SysConfig.ConfigPath, "Config", "管理员", this.confirmPassWord.Text);
                    oldPassWord.Text = "";
                    newPassWord.Text = "";
                    confirmPassWord.Text = "";
                    MessageBox.Show("修改成功");
                    this.Close();
                }
            }
           else if (this.cboUserName.Text == "开发人员" && this.oldPassWord.Text == Tool.IniFile.INIGetStringValue(SysConfig.ConfigPath, "Config", "开发人员", ""))
            {
                if (this.newPassWord.Text == this.confirmPassWord.Text)
                {
                    Tool.IniFile.INIWriteValue(SysConfig.ConfigPath, "Config", "开发人员", this.confirmPassWord.Text);
                    oldPassWord.Text = "";
                    newPassWord.Text = "";
                    confirmPassWord.Text = "";
                    MessageBox.Show("修改成功");
                    this.Close();
                }
            }
           else if (this.cboUserName.Text == "操作员" && this.oldPassWord.Text == Tool.IniFile.INIGetStringValue(SysConfig.ConfigPath, "Config", "操作员", ""))
            {
                if (this.newPassWord.Text == this.confirmPassWord.Text)
                {
                    Tool.IniFile.INIWriteValue(SysConfig.ConfigPath, "Config", "操作员", this.confirmPassWord.Text);
                    oldPassWord.Text = "";
                    newPassWord.Text = "";
                    confirmPassWord.Text = "";
                    MessageBox.Show("修改成功");
                    this.Close();
                }
            }
            else
            {
                oldPassWord.Text = "";
                newPassWord.Text = "";
                confirmPassWord.Text = "";
                //oldPassWord.Focus();
            }
        }
        
        //注销按钮
        public void btnLogout_Click(object sender, EventArgs e)
        {
            this.Close();

        }
    }
}
